package com.xiaobai.demo.utils;

/**
 * 响应数据类
 * zzj
 * 2025-5-8 23:51
 */
public class Result {
    private int code; //接口状态码
    private String msg; //接口返回消息

    private String comments; //数据备注
    private Object data; //响应内容


    public Result(int code, String msg, Object data, String comments) {
        this.code = code;
        this.msg = msg;
        this.comments = comments;
        this.data = data;
    }

    public static Result success(Object data, String comments) {
        Result item = new Result(200, "请求成功", data, comments);
        item.setData(data);
        return item;
    }

    public static Result failure(int errCode, String errorMessage) {
        return new Result(errCode, errorMessage, null, null);
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }


    public String getComments() {
        return comments;
    }

    public void setComments(String comments) {
        this.comments = comments;
    }

    @Override
    public String toString() {
        // 调整输出顺序，首先输出基本信息，然后是数据来源，最后是数据内容
        return "Result{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                ", comments='" + comments + '\'' +
                ", data=" + data +
                '}';
    }
}